// scripts.js
document.addEventListener('DOMContentLoaded', function() {
    // 为所有删除按钮添加事件监听器
    const deleteButtons = document.querySelectorAll('.delete-button');
    deleteButtons.forEach(button => {
        button.addEventListener('click', function() {
            const id = this.dataset.id;
            const type = this.dataset.type; // 'student', 'teacher', 'class', 'major'
            
            if (confirm(`确定要删除该${type}信息吗？`)) {
                fetch(`/${type}/${id}`, {
                    method: 'DELETE'
                })
                .then(response => response.json())
                .then(data => {
                    if (data.error) {
                        alert(data.error);
                    } else {
                        alert(data.message);
                        location.reload();
                    }
                })
                .catch(error => {
                    alert('删除失败，请稍后重试');
                });
            }
        });
    });
});